package com.soyorin.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soyorin.shop.entity.Shop;
import com.soyorin.shop.mapper.ShopMapper;
import com.soyorin.shop.service.ShopService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {

    @Override
    public List<Shop> selectByDistance(double positionX, double positionY) {
        // 验证坐标合法性
        if (positionX < -180 || positionX > 180) {
            throw new IllegalArgumentException("经度必须在-180到180之间");
        }
        if (positionY < -90 || positionY > 90) {
            throw new IllegalArgumentException("纬度必须在-90到90之间");
        }
        return baseMapper.selectByDistance(positionX, positionY);
    }

    @Override
    public List<Shop> selectByRatingDesc() {
        return baseMapper.selectByRatingDesc();
    }
}
